package com.feige.web.result;

import com.feige.base.vo.BaseVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Collections;
import java.util.List;

/**
 * @author feige
 */
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "返回列表")
@Data
public class ListResult<R extends BaseVo> extends BaseResult{

    private static final long serialVersionUID = 7545963134820966773L;
    @ApiModelProperty(
            value = "返回数据",
            example = "[]"
    )
    private List<R> data;

    public static  <R extends BaseVo> ListResult<R> success(List<R> data){
        ListResult<R> result = new ListResult<>();
        result.setSuccess();
        result.setData(data);
        return result;
    }

    public static  <R extends BaseVo> ListResult<R> failure(List<R> data){
        ListResult<R> result = new ListResult<>();
        result.setFailure();
        result.setData(data);
        return result;
    }

    public static <R extends BaseVo> ListResult<R> success(){
        return success(Collections.emptyList());
    }
    public static <R extends BaseVo> ListResult<R> failure(){
        return failure(null);
    }
}
